package com.zys.asseter.controller;

import com.zys.asseter.constant.FingerTypeConstant;
import com.zys.asseter.domain.dto.AssetFingerprintTypeDto;
import com.zys.asseter.service.AssetFingerprintTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/asm/asset-fingerprintType")
public class AssetFingerprintTypeController {

    private final AssetFingerprintTypeService assetFingerprintTypeService;

    @PostMapping("/insert")
    public void insert(@RequestBody AssetFingerprintTypeDto assetFingerprintTypeDto) {
        if(assetFingerprintTypeDto.getDimension().equalsIgnoreCase(FingerTypeConstant.FINGER_TYPE_MANUFACTURERS)){
            if(assetFingerprintTypeDto.getModelName()==null){
                throw new RuntimeException("选择或手动输入厂商");
            }
            assetFingerprintTypeService.insertForManufacturer(assetFingerprintTypeDto);
        }else if(assetFingerprintTypeDto.getDimension().equalsIgnoreCase(FingerTypeConstant.FINGER_TYPE) && assetFingerprintTypeDto.getParentModelId()==null){
            if(assetFingerprintTypeDto.getModelName()==null){
                throw new RuntimeException("选择或手动输入大类");
            }
            assetFingerprintTypeService.insertForType(assetFingerprintTypeDto);
        }else if(assetFingerprintTypeDto.getDimension().equalsIgnoreCase(FingerTypeConstant.FINGER_TYPE) && assetFingerprintTypeDto.getParentModelId()!=null){
            assetFingerprintTypeService.insertSubType(assetFingerprintTypeDto);
        }
    }
}
